package com.shop2cn.app.liveseller.testcase;

import com.shop2cn.app.liveseller.parameter.*;
import com.shop2cn.app.liveseller.service.*;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymttest.business.service.AuthCallServiceV2;
import com.ymttest.business.service.LiveRoomShop2cnCallService;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.livesellerShop2cn.*;
import com.ymttest.database.sqlwapper.livesellerShop2cn.LiveRoomShop2cnWapper;
import com.ymttest.utils.TestDataManager;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import org.apache.http.client.ClientProtocolException;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
*录制文件事件处理
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ReplayNotify{
	private static ReplayNotifyBean replaynotifyBean;
	private static ReplayNotifyCall replaynotifyCall;
	private static int sellerId ;
	private static String token ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("录制文件事件处理");
		try {
			sellerId = GodmchManageCallService.CreateSellerMch();
			token=AuthCallServiceV2.createToken(sellerId, "app");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		replaynotifyBean=new ReplayNotifyBean();
		replaynotifyCall=new ReplayNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(replaynotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_001() {
		Logger.start(true,"录制文件事件处理成功");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
		//	verifyPushStream(liveroom.getId());
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomShop2cnWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
			Logger.verifyEquals(replaynotifyBean.getData().getFileId(), m.get("FileId").toString(), "验证FileId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_002() {
		Logger.start(true,"EventType错误失败");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyBean.setEventType("err");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("500", replaynotifyCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_003() {
		Logger.start(true,"data.errorcode错误失败");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyBean.getData().setErrCode(-1);
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomShop2cnWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_004() {
		Logger.start(true,"data.FileId错误失败");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			replaynotifyBean.getData().setFileId("err");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("400", replaynotifyCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_005() {
		Logger.start(true,"data.processTaskList.TaskType错误失败");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setTaskType("err");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomShop2cnWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_006() {
		Logger.start(true,"data.processTaskList.errorcode错误失败");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setErrCode(-1);
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomShop2cnWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_007() {
		Logger.start(true,"data.processTaskList.Status错误失败");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setStatus("Failed");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomShop2cnWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_008() {
		Logger.start(true,"data.processTaskList.Definition错误失败");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
			Trancode sendto=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			sendto.setStatus("Failed");
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomShop2cnWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyNotEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ReplayNotify_009() {
		Logger.start(true,"录制文件事件处理成功,output.size为long型-http://jira.ymatou.cn:8080/browse/JIRACONN-30554");
		try {
			LiveRoom liveroom = LiveRoomShop2cnCallService.CreateSellerLive(LiveRoomShop2cnCallService.initCreatesellerliveBean(),sellerId);
			LiveRoomShop2cnCallService.UpdateLiveTimeToStart(liveroom.getId());
			Logger.comment("先推流再接受第三方通知");
			RecLiveNotifyBean recivenotifyBean = LiveRoomShop2cnCallService.initRecLiveNotifyBean(liveroom.getId(), 100);
			LiveRoomShop2cnCallService.LiveNotify(recivenotifyBean);
		//	verifyPushStream(liveroom.getId());
			replaynotifyBean = LiveRoomShop2cnCallService.initReplayNotifyBean(liveroom.getId(),recivenotifyBean.getFile_id());
//			Logger.debug(FormatUtil.beanToGSONString(replaynotifyBean));
			((Trancode) replaynotifyBean.getData().getProcessTaskList().get(0)).getOutput().setSize(Integer.MAX_VALUE+1l);;
//			Logger.debug(FormatUtil.beanToGSONString(replaynotifyBean));
			replaynotifyCall.setData(replaynotifyBean);
			replaynotifyCall.callService();			
			Logger.verifyEquals("0", replaynotifyCall.getString("code"), "验证code");
			Map m=new LiveRoomShop2cnWapper().selectLivereplayById(liveroom.getId().toString());
			Logger.debug(m);
			Trancode to=(Trancode) replaynotifyBean.getData().getProcessTaskList().get(0);
			Logger.verifyEquals(to.getOutput().getUrl(), m.get("ReplayBQUrl"), "验证ReplayBQUrl");
			Logger.verifyEquals(replaynotifyBean.getData().getFileId(), m.get("FileId").toString(), "验证FileId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}